//
//  ZSHomeListViewModel.swift
//  ZSWeibo
//
//  Created by zsj1992 on 16/4/12.
//  Copyright © 2016年 ichange. All rights reserved.
//

import UIKit

//这是一个home页的viewModel,负责home页的数据的管理

class ZSHomeListViewModel: NSObject {
    
    
    override init() {
        super.init()

        loadHomeData { (isSuccess, result) -> () in
            if isSuccess{
            
            self.arrayM = result
                
            }
        }
    }
    
    
    
    
    lazy var arrayM: [ZSStatus] = {
    
        let a = [ZSStatus]()
        
        return a
    }()
    

}




//HomeListViewModel提供的加载首页数据的方法

extension ZSHomeListViewModel{
   
    func loadHomeData(finished:(isSuccess:Bool,result:[ZSStatus])->()){
        
        ZSNetworkTools.sharedTools.loadHomeVCData((ZSUserAccountViewModel.sharedUserViewModel.userAccount?.access_token)!) { (result, error) -> () in
            
            guard let resultDic = result!["statuses"] as? [[String:AnyObject]] else{
                print("数据格式错误")
                return
            }
            
            var temp = [ZSStatus]()
            
            for dic in resultDic{
                
                let s = ZSStatus.init(dict: dic)
                
                temp.append(s)
                
            }
            

            finished(isSuccess: true,result: temp)
            
        }
    }

}
